import 'dart:async';

import 'package:flutter/services.dart';

enum TransitionMode {
  NULL,
  LEFT,
  RIGHT,
  TOP,
  BOTTOM
}

class RPConfigAndroid {
    String buttonTextColor;
    String errorTextColor;
    bool needSound;
    bool needWaitingForFinish;
    String promptTextColor;
    bool showWithDialog;
    String tipTextColor;
    TransitionMode transitionMode;
    String wavesBgColor;
    String wavesDetectingColor;

    Map<String, dynamic> toJson() {
      return {
        "buttonTextColor": buttonTextColor,
        "errorTextColor": errorTextColor,
        "needSound": needSound,
        "needWaitingForFinish": needWaitingForFinish,
        "promptTextColor": promptTextColor,
        "showWithDialog": showWithDialog,
        "tipTextColor": tipTextColor,
        "transitionMode": transitionMode?.index,
        "wavesBgColor": wavesBgColor,
        "wavesDetectingColor": wavesDetectingColor,
      };
    }
}

class RPResult {
  static const int AUDIT_EXCEPTION = -2;
  static const int AUDIT_NOT = -1;
  static const int AUDIT_IN_AUDIT = 0;
  static const int AUDIT_PASS = 1;
  static const int AUDIT_FAIL = 2;

  int code;
  String message;
  int state;

  RPResult.fromJson(Map<String, dynamic> json) {
    code = json["code"];
    message = json["message"];
    state = json["state"];
  }

  bool get isSuccess {
    return code == RPResult.AUDIT_PASS;
  }
}

class FlutterRpsdk {
  static const MethodChannel _channel =
      const MethodChannel('flutter_rpsdk');

  static Future init() async {
    await _channel.invokeMethod('init');
  }

  static Future androidStart(String token, RPConfigAndroid cofnig) async {
     Map<String, dynamic> result = await _channel.invokeMethod('start', {
      "token": token,
      "cofnig": cofnig.toJson(),
    });
     return RPResult.fromJson(result);
  }
  static Future androidStartByNative(String token, RPConfigAndroid cofnig) async {
    Map<String, dynamic> result = await _channel.invokeMethod('startByNative', {
      "token": token,
      "cofnig": cofnig.toJson(),
    });
    return RPResult.fromJson(result);
  }
}
